package com.ztgf.order.api.client;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.order.models.bo.OrderPayBO;
import com.ztgf.order.models.bo.OrderPayRelationBO;
import com.ztgf.order.models.dto.OrderPayRelationDTO;
import com.ztgf.order.models.service.IOrderPayRelationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 订单支付关联关系表控制器
 *
 * @author YUE
 * @Date 2020-06-23 10:34:22
 */

@RestController
@RequestMapping("/api/orderPayRelation")
@Slf4j
@Api(value = "OrderPayRelationApiController",tags = "订单支付关联关系表Api接口")
public class OrderPayRelationApiController {

    @DubboReference
    private IOrderPayRelationService orderPayRelationService;

    /**
     * 更新支付退款或者解冻的信息
     * @param orderPayBO
     * @return
     */
    @PostMapping("/updateOrderPayRelationInfo")
    @ApiOperation(value = "更新支付退款或者解冻的信息",notes = "更新支付退款或者解冻的信息")
    public Result<OrderPayRelationDTO> updateOrderPayRelationInfo(OrderPayBO orderPayBO){
        boolean b = orderPayRelationService.addOrderPayRelationInfo(orderPayBO);
        if(b){
            return new Result<>();
        }
        return new Result<>(CodeEnum.FAIL);
    }

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<OrderPayRelationDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        OrderPayRelationDTO dto = orderPayRelationService.selectById(id);

        return new Result<>(dto);
    }

    @ApiOperation(value = "订单支付关联关系表列表",notes = "订单支付关联关系表列表")
    @PostMapping("/queryPageList")
    public Result<Page<OrderPayRelationDTO>> queryPageList(OrderPayRelationBO bo){
        Wrapper<OrderPayRelationDTO> wrapper = new EntityWrapper<>();
        if (bo.getStartDate() != null){
            wrapper.ge("create_time", bo.getStartDate());
        }
        if (bo.getEndDate() != null){
            wrapper.le("create_time", bo.getEndDate());

        }
        Page<OrderPayRelationDTO> page = new Page<>(bo.getPageNo(), bo.getPageSize());
        page = orderPayRelationService.selectPage(page, wrapper);

        return new Result<>(page);
    }
}
